//
//  HttpTool.swift
//  WalkerLove
//
//  Created by Z on 2020/4/18.
//  Copyright © 2020 Carlson. All rights reserved.
//

import UIKit
import Alamofire

class HttpTool: NSObject {

    static func request(urlStr: String, method: HTTPMethod, params: [String: Any]?, completionHandler: @escaping(_ dict:[String: AnyObject]) -> (), errorHandle: @escaping(_ errorMsg: String) -> ()) {
        let header: HTTPHeaders = DeviceTool.configureRequestHeader()
        Alamofire.request(urlStr, method: method, parameters: params, encoding: URLEncoding.default, headers: header).response { (dataRes) in
            do {
                let json = try JSONSerialization.jsonObject(with: dataRes.data!, options: .mutableLeaves) as! [String: AnyObject]
                let code = json["code"] as! String
                if code.elementsEqual("200"){
                    completionHandler(json)
                }  
            }catch{
                
            }
        }
        
    }
}
